package cn.itcast.service.impl;

import cn.itcast.dao.MemberDao;
import cn.itcast.dao.OrderDao;
import cn.itcast.service.ReportService;
import cn.itcast.utils.DateUtils;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

//统计报表服务
@Service
public class ReportServiceImpl implements ReportService {

    //注入会员查询
    @Autowired
    private MemberDao memberDao;

    //注入预约查询
    @Autowired
    private OrderDao orderDao;


    @Override
    public Map<String, Object> getBusinessReportData() throws Exception {
        //创建要给map集合
        Map<String, Object> result = new HashMap<>();
        //获取今天日期
        String today = DateUtils.parseDate2String(DateUtils.getToday());
        //获取本周一的日期
        String thisWeekMonday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        //获取本月第一天的日期
        String firstDay4ThisMonth = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());

        //新增会员数
        Integer memberCountDate = memberDao.findMemberCountByDate(today);
        //总会员数
        Integer totalCount = memberDao.findMemberTotalCount();
        //本周会员数
        Integer thisWeekMember = memberDao.findMemberCountAfterDate(thisWeekMonday);
        //本月会员数
        Integer thisMonthMember = memberDao.findMemberCountAfterDate(firstDay4ThisMonth);

        //今日预约数
        Integer orderCountByDate = orderDao.findOrderCountBydate(today);
        //本周预约数
        Integer thisWeekOrder = orderDao.findOrderCountAfterdate(thisWeekMonday);
        //本月预约数
        Integer thisMonthOrder = orderDao.findOrderCountAfterdate(firstDay4ThisMonth);

        //今日到诊数
        Integer visitsCountBydate = orderDao.findVisitsCountBydate(today);
        //本周到诊数
        Integer visitsThisWeekOrder = orderDao.findVisitsCountAfterdate(thisWeekMonday);
        //本月到诊数
        Integer visitsThisMonthOrder = orderDao.findVisitsCountAfterdate(firstDay4ThisMonth);

        //热门套餐 取前四
        List<Map> hotSetmeal = orderDao.findHotSetmeal();


        //把数据都填充进集合 并返回
        result.put("reportDate",today); //今天日期
        result.put("todayNewMember",memberCountDate); //新增会员数
        result.put("totalMember",totalCount); //总会员数
        result.put("thisWeekNewMember",thisWeekMember); //本周新增会员数
        result.put("thisMonthNewMember",thisMonthMember); //本月新增会员数
        result.put("todayOrderNumber",orderCountByDate); //今日预约数
        result.put("todayVisitsNumber",visitsCountBydate); //今日到诊数
        result.put("thisWeekOrderNumber",thisWeekOrder); //本周预约数
        result.put("thisWeekVisitsNumber",visitsThisWeekOrder); //本周到诊数
        result.put("thisMonthOrderNumber",thisMonthOrder); //本月预约数
        result.put("thisMonthVisitsNumber",visitsThisMonthOrder); //本月到诊数
        result.put("hotSetmeal",hotSetmeal); //热门套餐,取前四
        //填充并返回
        return result;
    }
}

